home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / cli / Extract.lha / Extract.c next >
C/C++ Source or Header  |  1995-06-11  |  2KB  |  106 lines

  1. /*
  2.   Extract V1.00 11.06.1995
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #define english 1
  9. /* english 1 for english error messages, anything else for german */
  10.  
  11. const char ver[]  = "$VER: Extract 1.00 (11.06.1995)";
  12.  
  13.  
  14. void usage()
  15. {   printf("Usage: Extract <infile> <outfile> <from:bytes> <to:bytes>\n");
  16. }
  17.  
  18. void fin_error()
  19. #if english == 1
  20. {   printf("Can't open input file.\n"); }
  21. #else
  22. {   printf("Kann Eingabedatei nicht öffnen.\n"); }
  23. #endif
  24.  
  25. void fout_error()
  26. #if english == 1
  27. {   printf("Can't open output file.\n"); }
  28. #else
  29. {   printf("Kann Ausgabedatei nicht öffnen.\n"); }
  30. #endif
  31.  
  32.  
  33. void fout_exits()
  34. #if english == 1
  35. {   printf("output file exists!\n"); }
  36. #else
  37. {   printf("Ausgabedatei existiert schon!\n"); }
  38. #endif
  39.  
  40. main(argc,argv)
  41. int argc;
  42. char *argv[];
  43. {   int    i,a,b;
  44.     FILE *in,*out;
  45.     char ch;
  46.  
  47.     printf ("%s\n",ver+6);
  48.     printf ("(C)1995 Christian Steigies (steigies@physik.uni-kiel.d400.de)\n");
  49.     printf ("Freeware, NO commercial usage ;-)\n\n");
  50.  
  51.     if  (argc!=5)
  52.     {   atexit(&usage);
  53.         exit(EXIT_SUCCESS);
  54.     }
  55.  
  56.     if  ((in=fopen(argv[1],"r"))==0) /* Eingabefile zum lesen öffnen */
  57.     {   atexit(&usage);
  58.         atexit(&fin_error);
  59.         exit(EXIT_SUCCESS);
  60.     }
  61.  
  62.     a=atoi(argv[3]);
  63.     b=atoi(argv[4]);
  64.     if  (a<1)
  65.  
  66. #if english == 1
  67.     {   printf("<from> must be >= 1 !\n");
  68. #else
  69.     {   printf("<from> muss >= 1 sein!\n");
  70. #endif
  71.         atexit(&usage);
  72.         exit(EXIT_SUCCESS);
  73.     }
  74.     else if  (b<a)
  75.  
  76. #if english == 1
  77.     {   printf("<to> must be >= <from> !\n");
  78. #else
  79.     {   printf("<to> muss >= <from> sein!\n");
  80. #endif
  81.         atexit(&usage);
  82.         exit(EXIT_SUCCESS);
  83.     }
  84.  
  85.     if  ((out=fopen(argv[2],"r"))==0) /* Ausgabefile öffnen */
  86.     {
  87.         if  ((out=fopen(argv[2],"w"))==0)
  88.         {   atexit(&usage); atexit(&fout_error); exit(EXIT_SUCCESS); }
  89.     }
  90.     else /* file existiert schon! */
  91.     {   atexit(&usage); atexit(&fout_exits); exit(EXIT_SUCCESS); }
  92.  
  93.     printf("extracting %s from %i to %i into file %s\n",argv[1],a,b,argv[2]);
  94.  
  95.     i=0;
  96.     do
  97.     {   ch=getc(in);
  98.         i++;
  99.         if  ((i>=a) && (i<=b) && !feof(in)) fputc(ch,out);
  100.     }   while   (!feof(in));
  101.     fclose(in);
  102.     printf("Ready.\n");
  103.     exit(EXIT_SUCCESS);
  104.  
  105. }
  106.